package com.leetcode.shuzu;

import java.util.Arrays;
import java.util.HashMap;

public class TwoSumTest {
    public static void main(String[] args) {
        int[] nums = {2,7,11,15};
        //int[] ints = twoSum(nums, 200);
        int[] ints1 = twoSum2(nums, 9);
        System.out.println(Arrays.toString(ints1));
    }

    private static int[] twoSum2(int[] nums, int target) {
        HashMap<Integer,Integer> hm = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            if ((hm.containsKey(target - nums[i]))){
                return  new int[]{hm.get(target-nums[i]),i};
            }
            hm.put(nums[i],i);
        }
        return new int[0];
    }

    public static int[] twoSum(int[] nums, int target) {
        for (int i = 0; i < nums.length; i++) {
            for (int j = i+1; j < nums.length; j++) {
                if((nums[i] + nums[j]) == target){
                    return new int[]{i,j};
                }
            }
        }
        return new int[0];
    }
}
